export default{
  namespaced :true,
  //数据
  state:() =>({
    resourseUrl : 'https://7072-prod-2gdjc66eb3276dce-1311299937.tcb.qcloud.la',
    address:JSON.parse(uni.getStorageSync('address') || '{}'),
    //登陸成功后的token
    token: uni.getStorageSync('token') || '',
    userInfo: JSON.parse(uni.getStorageSync('userInfo') || '{}'),
    //重定向
    redirectInfo:null
  }),
  
  mutations:{
    updateAddress(state, address){
      state.address = address
      this.commit('user/saveAddressToStorage')
    },
    //存地址到本地
    saveAddressToStorage(state){
      uni.setStorageSync('address', JSON.stringify(state.address))
    },
    updateUserInformation(state, userInfo){
      state.userInfo = userInfo
      this.commit('user/saveUserInformation')
    },
    saveUserInformation(state){
      uni.setStorageSync('userInfo', JSON.stringify(state.userInfo))
    },
    updateToken(state,token){
      state.token = token
      this.commit('user/saveTokenToStorage')
    },
    saveTokenToStorage(state){
      uni.setStorageSync('token', state.token)
    },
    updateRedirectInfo(state, info){
      state.redirectInfo = info
    }
  },
  getters:{
    //地址的拼接
    addressStr(state){
      if(!state.address.provinceName) return ''
      return state.address.provinceName+state.address.cityName+state.address.countyName + state.address.detailInfo
    }
  }
}